﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CommunitySystemModel;
using System.Data;
using System.Data.SqlClient;

namespace CommunitySystem.BO.SystemManager
{
    public class MQCJManangerBO
    {
        AccessHelper ah = new AccessHelper();

        #region RKXX

        private DateTime GetCsrqBySfzh(string sfzh)
        {
            DateTime csrq = DateTime.Now;
            if (sfzh.Length == 18)
            {
                csrq = DateTime.Parse(sfzh.Substring(6, 4) + sfzh.Substring(10, 2) + sfzh.Substring(12, 2));
            }
            else if (sfzh.Length == 15)
            {
                csrq = DateTime.Parse("19" + sfzh.Substring(6, 2) + sfzh.Substring(8, 2) + sfzh.Substring(10, 2));
            }
            else
                csrq = DateTime.Parse("1900-01-01");

            return csrq;

        }
        public List<RKXXViewDb> GetRKXXViewDbByCondition(string nameStr, int xb, string sfz, List<string> mqlx,
            List<string> zylb, string zzmm = "", string judz = "", string rklb = "", string hjdz = "", string xz = "", string whcd = "", DateTime? sDate = null, DateTime? eDate = null)
        {
            string sql = string.Format(@"select ID,XM,(case when XB=1 then '男' else '女' end) as XB,
            ZJHM,MZ,ZZMM,LXFS,MQLB as FWLB,JZDXZ,isnull((select top 1 DictCode from DataDictionaryItem where id=RKLB ),'') RKLB,JG,YHZGX from BAS_RKXX as bsRkxx where 1=1 ");


            if (!string.IsNullOrEmpty(sfz))
            {
                sql += " and ZJHM like '%" + sfz + "%'";
            }

            if (!string.IsNullOrEmpty(nameStr))
            {
                sql += " and Xm like '%" + nameStr + "%'";
            }

            if (xb != -1)
            {
                sql += " and XB=" + xb.ToString();
            }

            if (mqlx != null && mqlx.Count != 0)
            {
                sql += " and (";
                foreach (var item in mqlx)
                {
                    sql += "CHARINDEX('," + item + ",',marc.BFLB,0)>0 and ";
                }
                sql = sql.Substring(0, sql.Length - 4) + ") ";

            }

            if (zylb != null && zylb.Count != 0)
            {
                sql += " and (";
                foreach (var item in zylb)
                {
                    sql += "CHARINDEX('," + item + ",',marc.ZYLB,0)>0 and ";
                }
                sql = sql.Substring(0, sql.Length - 4) + ")";
            }

            if (!string.IsNullOrEmpty(zzmm))
            {
                sql += " and CHARINDEX(','+ZZMM+',','," + zzmm + ",',0)>0";
            }

            if (!string.IsNullOrEmpty(judz))
            {
                sql += " and JZDXZ like '%" + judz + "%' ";
            }

            if (!string.IsNullOrEmpty(rklb) && rklb != "全部")
            {
                sql += " and RKLB ='" + rklb + "' ";
            }

            if (!string.IsNullOrEmpty(hjdz))
            {
                sql += " and HJDXZ like '%" + hjdz + "%' ";
            }

            if (!string.IsNullOrEmpty(xz) && xz != "全部")
            {
                sql += " and XZ='" + xz + "' ";
            }

            if (!string.IsNullOrEmpty(whcd) && whcd != "全部")
            {
                sql += " and WHCD='" + whcd + "' ";
            }


            if (sDate.HasValue && sDate.Value != DateTime.MinValue)
            {
                string sDStr = sDate.Value.ToString("yyyy-MM-dd");

                sql += @" and CSRQ>='" + sDStr + "' ";
            }


            if (eDate.HasValue && eDate.Value != DateTime.MinValue)
            {
                string eDStr = eDate.Value.ToString("yyyy-MM-dd");

                sql += @" and CSRQ<='" + eDStr + "' ";
            }

            List<RKXXViewDb> ar = new List<RKXXViewDb>();
            sql += " order by ZXGXSJ desc";
            var ds = ah.ExcuteDataSet(sql);
            if (ds == null || ds.Tables.Count < 1)
                return null;
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                RKXXViewDb ac = new RKXXViewDb()
                {
                    ID = Int32.Parse(dr["ID"].ToString()),
                    XM = dr["XM"] == DBNull.Value ? "" : dr["XM"].ToString(),
                    XB = dr["XB"] == DBNull.Value ? "" : dr["XB"].ToString(),
                    FWLB = dr["FWLB"] == DBNull.Value ? "" : dr["FWLB"].ToString(),
                    MZ = dr["MZ"] == DBNull.Value ? "" : dr["MZ"].ToString(),
                    JG = dr["JG"] == DBNull.Value ? "" : dr["JG"].ToString(),
                    JZDXZ = dr["JZDXZ"] == DBNull.Value ? "" : dr["JZDXZ"].ToString(),
                    ZJHM = dr["ZJHM"] == DBNull.Value ? "" : dr["ZJHM"].ToString(),
                    ZZMM = dr["ZZMM"] == DBNull.Value ? "" : dr["ZZMM"].ToString(),
                    LXFS = dr["LXFS"] == DBNull.Value ? "" : dr["LXFS"].ToString(),
                    RKLB = dr["RKLB"] == DBNull.Value ? "" : dr["RKLB"].ToString(),
                    YHZGX = dr["YHZGX"] == DBNull.Value ? "" : dr["YHZGX"].ToString()
                };
                ar.Add(ac);
            }

            return ar;
        }

        public BAS_RKXXModel GetBAS_RKXXModelByID(int id)
        {
            BAS_RKXXModel cuBsRkxx = new BAS_RKXXModel();
            string sql = string.Format("select * from [BAS_RKXX] where Id={0}", id);
            var ds = ah.GetDataSet(sql);
            if (ds != null && ds.Rows.Count > 0)
            {
                DataRow dr = ds.Rows[0];

                cuBsRkxx.ID = Int32.Parse(dr["ID"].ToString());
                cuBsRkxx.BYZK = dr["BYZK"] == DBNull.Value ? "" : dr["BYZK"].ToString();
                cuBsRkxx.BZ = dr["BZ"] == DBNull.Value ? "" : dr["BZ"].ToString();
                cuBsRkxx.CSD = dr["CSD"] == DBNull.Value ? "" : dr["CSD"].ToString();
                cuBsRkxx.CSRQ = dr["CSRQ"] == DBNull.Value ? (DateTime?)null : DateTime.Parse(dr["CSRQ"].ToString());
                cuBsRkxx.CYM = dr["CYM"] == DBNull.Value ? "" : dr["CYM"].ToString();
                cuBsRkxx.GJ = dr["GJ"] == DBNull.Value ? "" : dr["GJ"].ToString();
                cuBsRkxx.GZDW = dr["GZDW"] == DBNull.Value ? "" : dr["GZDW"].ToString();
                cuBsRkxx.HJDEJMP = dr["HJDEJMP"] == DBNull.Value ? "" : dr["HJDEJMP"].ToString();
                cuBsRkxx.HJDEJMPDSH = dr["HJDEJMPDSH"] == DBNull.Value ? "" : dr["HJDEJMPDSH"].ToString();
                cuBsRkxx.HJDLM = dr["HJDLM"] == DBNull.Value ? "" : dr["HJDLM"].ToString();
                cuBsRkxx.HJDXZ = dr["HJDXZ"] == DBNull.Value ? "" : dr["HJDXZ"].ToString();
                cuBsRkxx.HJDXZQH = dr["HJDXZQH"] == DBNull.Value ? "" : dr["HJDXZQH"].ToString();
                cuBsRkxx.HJDYJMP = dr["HJDYJMP"] == DBNull.Value ? "" : dr["HJDYJMP"].ToString();
                cuBsRkxx.HJDYJMPDSH = dr["HJDYJMPDSH"] == DBNull.Value ? "" : dr["HJDYJMPDSH"].ToString();
                cuBsRkxx.HJFWID = dr["HJFWID"] == DBNull.Value ? 0 : Int32.Parse(dr["HJFWID"].ToString());
                cuBsRkxx.HJLB = dr["HJLB"] == DBNull.Value ? 0 : Int32.Parse(dr["HJLB"].ToString());
                cuBsRkxx.HYZK = dr["HYZK"] == DBNull.Value ? 0 : Int32.Parse(dr["HYZK"].ToString());
                cuBsRkxx.JG = dr["JG"] == DBNull.Value ? "" : dr["JG"].ToString();
                cuBsRkxx.JKZK = dr["JKZK"] == DBNull.Value ? "" : dr["JKZK"].ToString();
                cuBsRkxx.JZDEJMP = dr["JZDEJMP"] == DBNull.Value ? "" : dr["JZDEJMP"].ToString();
                cuBsRkxx.JZDEJMPDSH = dr["JZDEJMPDSH"] == DBNull.Value ? "" : dr["JZDEJMPDSH"].ToString();
                cuBsRkxx.JZDLM = dr["JZDLM"] == DBNull.Value ? "" : dr["JZDLM"].ToString();
                cuBsRkxx.JZDXZ = dr["JZDXZ"] == DBNull.Value ? "" : dr["JZDXZ"].ToString();
                cuBsRkxx.JZDXZQH = dr["JZDXZQH"] == DBNull.Value ? "" : dr["JZDXZQH"].ToString();
                cuBsRkxx.JZDYJMP = dr["JZDYJMP"] == DBNull.Value ? "" : dr["JZDYJMP"].ToString();
                cuBsRkxx.JZDYJMPDSH = dr["JZDYJMPDSH"] == DBNull.Value ? "" : dr["JZDYJMPDSH"].ToString();
                cuBsRkxx.JZFWID = dr["JZFWID"] == DBNull.Value ? 0 : Int32.Parse(dr["JZFWID"].ToString());
                cuBsRkxx.LXFS = dr["LXFS"] == DBNull.Value ? "" : dr["LXFS"].ToString();
                cuBsRkxx.MAPID = dr["MAPID"] == DBNull.Value ? 0 : Int32.Parse(dr["MAPID"].ToString());
                cuBsRkxx.MQLB = dr["MQLB"] == DBNull.Value ? "" : dr["MQLB"].ToString();
                cuBsRkxx.MZ = dr["MZ"] == DBNull.Value ? "" : dr["MZ"].ToString();
                cuBsRkxx.POXM = dr["POXM"] == DBNull.Value ? "" : dr["POXM"].ToString();
                cuBsRkxx.POZJHM = dr["POZJHM"] == DBNull.Value ? "" : dr["POZJHM"].ToString();
                cuBsRkxx.RKLB = dr["RKLB"] == DBNull.Value ? 0 : Int32.Parse(dr["RKLB"].ToString());
                cuBsRkxx.SG = dr["SG"] == DBNull.Value ? "" : dr["SG"].ToString();
                cuBsRkxx.SSCJ = dr["SSCJ"] == DBNull.Value ? 0 : Int32.Parse(dr["SSCJ"].ToString());
                cuBsRkxx.WHCD = dr["WHCD"] == DBNull.Value ? "" : dr["WHCD"].ToString();
                cuBsRkxx.XB = dr["XB"] == DBNull.Value ? 0 : Int32.Parse(dr["XB"].ToString());
                cuBsRkxx.XM = dr["XM"] == DBNull.Value ? "" : dr["XM"].ToString();
                cuBsRkxx.XMQP = dr["XMQP"] == DBNull.Value ? "" : dr["XMQP"].ToString();
                cuBsRkxx.XMSP = dr["XMSP"] == DBNull.Value ? "" : dr["XMSP"].ToString();
                cuBsRkxx.XX = dr["XX"] == DBNull.Value ? "" : dr["XX"].ToString();
                cuBsRkxx.XZ = dr["XZ"] == DBNull.Value ? "" : dr["XZ"].ToString();
                cuBsRkxx.YHZGX = dr["YHZGX"] == DBNull.Value ? "" : dr["YHZGX"].ToString();
                cuBsRkxx.ZJHM = dr["ZJHM"] == DBNull.Value ? "" : dr["ZJHM"].ToString();
                cuBsRkxx.ZJXY = dr["ZJXY"] == DBNull.Value ? "" : dr["ZJXY"].ToString();
                cuBsRkxx.ZJZL = dr["ZJZL"] == DBNull.Value ? 0 : Int32.Parse(dr["ZJZL"].ToString());
                cuBsRkxx.ZT = dr["ZT"] == DBNull.Value ? 0 : Int32.Parse(dr["ZT"].ToString());
                cuBsRkxx.ZXGXSJ = dr["ZXGXSJ"] == DBNull.Value ? (DateTime?)null : DateTime.Parse(dr["ZXGXSJ"].ToString());
                cuBsRkxx.ZY = dr["ZY"] == DBNull.Value ? "" : dr["ZY"].ToString();
                cuBsRkxx.ZYLB = dr["ZYLB"] == DBNull.Value ? "" : dr["ZYLB"].ToString();
                cuBsRkxx.ZZMM = dr["ZZMM"] == DBNull.Value ? "" : dr["ZZMM"].ToString();
                cuBsRkxx.FwId = dr["FwId"] == DBNull.Value ? 0 : Int32.Parse(dr["FwId"].ToString());

            }
            return cuBsRkxx;
        }

        public int InsertBAS_RKXXModel(BAS_RKXXModel rkxxModel, List<RKXXFamilyMemberActionObj> cuMembers = null)
        {
            if (rkxxModel == null)
                return 0;

            int resu = 0;
            System.Data.SqlClient.SqlConnection cnn = new System.Data.SqlClient.SqlConnection(ah.GetConnectionStr());
            System.Data.SqlClient.SqlCommand cm = cnn.CreateCommand();
            cnn.Open();
            System.Data.SqlClient.SqlTransaction trans = cnn.BeginTransaction();
            cm.Transaction = trans;
            try
            {
                //arc.CSRQ = GetCsrqBySfzh(arc.GMSFZHM);
                string sql = @"INSERT INTO [BAS_RKXX]
           ([XM],[XB],[MZ],[CSRQ],[ZJHM],[MQLB],[ZYLB],[SSCJ],[RKLB],[HJLB],[ZT],[JG],[CSD],[WHCD],[HYZK],
           [JKZK],[ZZMM],[LXFS],[GZDW],[XZ],[YHZGX],[ZXGXSJ],[ZJZL],[XMQP],[XMSP],[CYM],[HJDXZQH],[HJDLM],
           [HJDXZ],[HJDYJMP],[HJDYJMPDSH],[HJDEJMP],[HJDEJMPDSH],[JZDXZQH],[JZDLM],[JZDXZ],[JZDYJMP],
           [JZDYJMPDSH],[JZDEJMP],[JZDEJMPDSH],[POXM],[POZJHM],[ZY],[ZJXY],[BYZK],[SG],[XX],[GJ],[MAPID],
           [HJFWID],[JZFWID],[BZ],[FwId])
            VALUES  (@XM,@XB,@MZ,@CSRQ,@ZJHM,@MQLB,@ZYLB,@SSCJ,@RKLB,@HJLB,@ZT,@JG,@CSD,@WHCD,@HYZK,
            @JKZK,@ZZMM,@LXFS,@GZDW,@XZ,@YHZGX,@ZXGXSJ,@ZJZL,@XMQP,@XMSP,@CYM,@HJDXZQH,@HJDLM,
            @HJDXZ,@HJDYJMP,@HJDYJMPDSH,@HJDEJMP,@HJDEJMPDSH,@JZDXZQH,@JZDLM,@JZDXZ,@JZDYJMP,
            @JZDYJMPDSH,@JZDEJMP,@JZDEJMPDSH,@POXM,@POZJHM,@ZY,@ZJXY,@BYZK,@SG,@XX,@GJ,@MAPID,
            @HJFWID,@JZFWID,@BZ,@FwId) SELECT  @@IDENTITY  as  ID";
                SqlParameter[] sqlparams = new SqlParameter[]
            {
                new SqlParameter(){ParameterName="@XM", Value = rkxxModel.XM},
                new SqlParameter(){ParameterName="@XB", Value = rkxxModel.XB},
                new SqlParameter(){ParameterName="@MZ", Value = rkxxModel.MZ==null?"":rkxxModel.MZ},
                new SqlParameter(){ParameterName="@CSRQ", Value = rkxxModel.CSRQ==null?"":rkxxModel.CSRQ.Value.ToString("yyyy-MM-dd HH:mm:ss")},
                new SqlParameter(){ParameterName="@ZJHM", Value = rkxxModel.ZJHM==null?"":rkxxModel.ZJHM},
                new SqlParameter(){ParameterName="@MQLB", Value = rkxxModel.MQLB==null?"":rkxxModel.MQLB},
                new SqlParameter(){ParameterName="@ZYLB", Value = rkxxModel.ZYLB==null?"":rkxxModel.ZYLB},
                new SqlParameter(){ParameterName="@SSCJ", Value = rkxxModel.SSCJ},
                new SqlParameter(){ParameterName="@RKLB", Value = rkxxModel.RKLB},
                new SqlParameter(){ParameterName="@HJLB", Value = rkxxModel.HJLB},
                new SqlParameter(){ParameterName="@ZT", Value = rkxxModel.ZT},
                new SqlParameter(){ParameterName="@JG", Value = rkxxModel.JG==null?"":rkxxModel.JG},
                new SqlParameter(){ParameterName="@CSD", Value = rkxxModel.CSD==null?"":rkxxModel.CSD},
                new SqlParameter(){ParameterName="@WHCD", Value = rkxxModel.WHCD==null?"":rkxxModel.WHCD},
                new SqlParameter(){ParameterName="@HYZK", Value = rkxxModel.HYZK},              

                new SqlParameter(){ParameterName="@JKZK", Value = rkxxModel.JKZK==null?"":rkxxModel.JKZK},
                new SqlParameter(){ParameterName="@ZZMM", Value = rkxxModel.ZZMM==null?"":rkxxModel.ZZMM},
                new SqlParameter(){ParameterName="@LXFS", Value = rkxxModel.LXFS==null?"":rkxxModel.LXFS},
                new SqlParameter(){ParameterName="@GZDW", Value = rkxxModel.GZDW==null?"":rkxxModel.GZDW},
                new SqlParameter(){ParameterName="@XZ", Value = rkxxModel.XZ==null?"":rkxxModel.XZ},
                new SqlParameter(){ParameterName="@YHZGX", Value = rkxxModel.YHZGX==null?"":rkxxModel.YHZGX},
                new SqlParameter(){ParameterName="@ZXGXSJ", Value = rkxxModel.ZXGXSJ==null?"":rkxxModel.ZXGXSJ.Value.ToString("yyyy-MM-dd HH:mm:ss")},
                new SqlParameter(){ParameterName="@ZJZL", Value = rkxxModel.ZJZL},
                new SqlParameter(){ParameterName="@XMQP", Value = rkxxModel.XMQP==null?"":rkxxModel.XMQP},
                new SqlParameter(){ParameterName="@XMSP", Value = rkxxModel.XMSP==null?"":rkxxModel.XMSP},
                new SqlParameter(){ParameterName="@CYM", Value = rkxxModel.CYM==null?"":rkxxModel.CYM},
                new SqlParameter(){ParameterName="@HJDXZQH", Value = rkxxModel.HJDXZQH==null?"":rkxxModel.HJDXZQH},
                new SqlParameter(){ParameterName="@HJDLM", Value = rkxxModel.HJDLM==null?"":rkxxModel.HJDLM},
                                
                new SqlParameter(){ParameterName="@HJDXZ", Value = rkxxModel.HJDXZ==null?"":rkxxModel.HJDXZ},
                new SqlParameter(){ParameterName="@HJDYJMP", Value = rkxxModel.HJDYJMP==null?"":rkxxModel.HJDYJMP},
                new SqlParameter(){ParameterName="@HJDYJMPDSH", Value = rkxxModel.HJDYJMPDSH==null?"":rkxxModel.HJDYJMPDSH},
                new SqlParameter(){ParameterName="@HJDEJMP", Value = rkxxModel.HJDEJMP==null?"":rkxxModel.HJDEJMP},
                new SqlParameter(){ParameterName="@HJDEJMPDSH", Value = rkxxModel.HJDEJMPDSH==null?"":rkxxModel.HJDEJMPDSH},
                new SqlParameter(){ParameterName="@JZDXZQH", Value = rkxxModel.JZDXZQH==null?"":rkxxModel.JZDXZQH},
                new SqlParameter(){ParameterName="@JZDLM", Value = rkxxModel.JZDLM==null?"":rkxxModel.JZDLM},
                new SqlParameter(){ParameterName="@JZDXZ", Value = rkxxModel.JZDXZ==null?"":rkxxModel.JZDXZ},
                new SqlParameter(){ParameterName="@JZDYJMP", Value = rkxxModel.JZDYJMP==null?"":rkxxModel.JZDYJMP},
                 
                new SqlParameter(){ParameterName="@JZDYJMPDSH", Value = rkxxModel.JZDYJMPDSH==null?"":rkxxModel.JZDYJMPDSH},
                new SqlParameter(){ParameterName="@JZDEJMP", Value = rkxxModel.JZDEJMP==null?"":rkxxModel.JZDEJMP},
                new SqlParameter(){ParameterName="@JZDEJMPDSH", Value = rkxxModel.JZDEJMPDSH==null?"":rkxxModel.JZDEJMPDSH},
                new SqlParameter(){ParameterName="@POXM", Value = rkxxModel.POXM==null?"":rkxxModel.POXM},
                new SqlParameter(){ParameterName="@POZJHM", Value = rkxxModel.POZJHM==null?"":rkxxModel.POZJHM},
                new SqlParameter(){ParameterName="@ZY", Value = rkxxModel.ZY==null?"":rkxxModel.ZY},
                new SqlParameter(){ParameterName="@ZJXY", Value = rkxxModel.ZJXY==null?"":rkxxModel.ZJXY},
                new SqlParameter(){ParameterName="@BYZK", Value = rkxxModel.BYZK==null?"":rkxxModel.BYZK},
                new SqlParameter(){ParameterName="@SG", Value = rkxxModel.SG==null?"":rkxxModel.SG},
                new SqlParameter(){ParameterName="@XX", Value = rkxxModel.XX==null?"":rkxxModel.XX},
                new SqlParameter(){ParameterName="@GJ", Value = rkxxModel.GJ==null?"":rkxxModel.GJ},
                new SqlParameter(){ParameterName="@MAPID", Value = rkxxModel.MAPID},

                new SqlParameter(){ParameterName="@HJFWID", Value = rkxxModel.HJFWID},
                new SqlParameter(){ParameterName="@JZFWID", Value = rkxxModel.JZFWID},
                new SqlParameter(){ParameterName="@BZ", Value = rkxxModel.BZ==null?"":rkxxModel.BZ},
                new SqlParameter(){ParameterName="@FwId", Value = rkxxModel.FwId}
                               

            };
                cm.CommandText = sql;
                cm.Parameters.Clear();
                cm.Parameters.AddRange(sqlparams);
                var re = cm.ExecuteScalar();

                int cuId = Int32.Parse(re.ToString());
                if (cuMembers != null && cuMembers.Count > 0)
                {
                    foreach (var item in cuMembers)
                    {
                        if (item.ActionMode != 2)
                        {
                            //item.CuRKXX.CSRQ = GetCsrqBySfzh(item.CuAch.GMSFZHM);
                            //item.CuAch.ParentID = cuId;
                            sql = @"INSERT INTO [BAS_RKXX]
           ([XM],[XB],[MZ],[CSRQ],[ZJHM],[MQLB],[ZYLB],[SSCJ],[RKLB],[HJLB],[ZT],[JG],[CSD],[WHCD],[HYZK],
           [JKZK],[ZZMM],[LXFS],[GZDW],[XZ],[YHZGX],[ZXGXSJ],[ZJZL],[XMQP],[XMSP],[CYM],[HJDXZQH],[HJDLM],
           [HJDXZ],[HJDYJMP],[HJDYJMPDSH],[HJDEJMP],[HJDEJMPDSH],[JZDXZQH],[JZDLM],[JZDXZ],[JZDYJMP],
           [JZDYJMPDSH],[JZDEJMP],[JZDEJMPDSH],[POXM],[POZJHM],[ZY],[ZJXY],[BYZK],[SG],[XX],[GJ],[MAPID],
           [HJFWID],[JZFWID],[BZ],[FwId])
            VALUES  (@XM,@XB,@MZ,@CSRQ,@ZJHM,@MQLB,@ZYLB,@SSCJ,@RKLB,@HJLB,@ZT,@JG,@CSD,@WHCD,@HYZK,
            @JKZK,@ZZMM,@LXFS,@GZDW,@XZ,@YHZGX,@ZXGXSJ,@ZJZL,@XMQP,@XMSP,@CYM,@HJDXZQH,@HJDLM,
            @HJDXZ,@HJDYJMP,@HJDYJMPDSH,@HJDEJMP,@HJDEJMPDSH,@JZDXZQH,@JZDLM,@JZDXZ,@JZDYJMP,
            @JZDYJMPDSH,@JZDEJMP,@JZDEJMPDSH,@POXM,@POZJHM,@ZY,@ZJXY,@BYZK,@SG,@XX,@GJ,@MAPID,
            @HJFWID,@JZFWID,@BZ,@FwId) SELECT  @@IDENTITY  as  ID";
                            sqlparams = new SqlParameter[]
            {
                new SqlParameter(){ParameterName="@XM", Value = item.CuRKXX.XM},
                new SqlParameter(){ParameterName="@XB", Value = item.CuRKXX.XB},
                new SqlParameter(){ParameterName="@MZ", Value = item.CuRKXX.MZ==null?"":item.CuRKXX.MZ},
                new SqlParameter(){ParameterName="@CSRQ", Value = item.CuRKXX.CSRQ==null?"":item.CuRKXX.CSRQ.Value.ToString("yyyy-MM-dd HH:mm:ss")},
                new SqlParameter(){ParameterName="@ZJHM", Value = item.CuRKXX.ZJHM==null?"":item.CuRKXX.ZJHM},
                new SqlParameter(){ParameterName="@MQLB", Value = item.CuRKXX.MQLB==null?"":item.CuRKXX.MQLB},
                new SqlParameter(){ParameterName="@ZYLB", Value = item.CuRKXX.ZYLB==null?"":item.CuRKXX.ZYLB},
                new SqlParameter(){ParameterName="@SSCJ", Value = item.CuRKXX.SSCJ},
                new SqlParameter(){ParameterName="@RKLB", Value = item.CuRKXX.RKLB},
                new SqlParameter(){ParameterName="@HJLB", Value = item.CuRKXX.HJLB},
                new SqlParameter(){ParameterName="@ZT", Value = item.CuRKXX.ZT},
                new SqlParameter(){ParameterName="@JG", Value = item.CuRKXX.JG==null?"":item.CuRKXX.JG},
                new SqlParameter(){ParameterName="@CSD", Value = item.CuRKXX.CSD==null?"":item.CuRKXX.CSD},
                new SqlParameter(){ParameterName="@WHCD", Value = item.CuRKXX.WHCD==null?"":item.CuRKXX.WHCD},
                new SqlParameter(){ParameterName="@HYZK", Value = item.CuRKXX.HYZK},              

                new SqlParameter(){ParameterName="@JKZK", Value = item.CuRKXX.JKZK==null?"":item.CuRKXX.JKZK},
                new SqlParameter(){ParameterName="@ZZMM", Value = item.CuRKXX.ZZMM==null?"":item.CuRKXX.ZZMM},
                new SqlParameter(){ParameterName="@LXFS", Value = item.CuRKXX.LXFS==null?"":item.CuRKXX.LXFS},
                new SqlParameter(){ParameterName="@GZDW", Value = item.CuRKXX.GZDW==null?"":item.CuRKXX.GZDW},
                new SqlParameter(){ParameterName="@XZ", Value = item.CuRKXX.XZ==null?"":item.CuRKXX.XZ},
                new SqlParameter(){ParameterName="@YHZGX", Value = item.CuRKXX.YHZGX==null?"":item.CuRKXX.YHZGX},
                new SqlParameter(){ParameterName="@ZXGXSJ", Value = item.CuRKXX.ZXGXSJ==null?"":item.CuRKXX.ZXGXSJ.Value.ToString("yyyy-MM-dd HH:mm:ss")},
                new SqlParameter(){ParameterName="@ZJZL", Value = item.CuRKXX.ZJZL},
                new SqlParameter(){ParameterName="@XMQP", Value = item.CuRKXX.XMQP==null?"":item.CuRKXX.XMQP},
                new SqlParameter(){ParameterName="@XMSP", Value = item.CuRKXX.XMSP==null?"":item.CuRKXX.XMSP},
                new SqlParameter(){ParameterName="@CYM", Value = item.CuRKXX.CYM==null?"":item.CuRKXX.CYM},
                new SqlParameter(){ParameterName="@HJDXZQH", Value = item.CuRKXX.HJDXZQH==null?"":item.CuRKXX.HJDXZQH},
                new SqlParameter(){ParameterName="@HJDLM", Value = item.CuRKXX.HJDLM==null?"":item.CuRKXX.HJDLM},
                                
                new SqlParameter(){ParameterName="@HJDXZ", Value = item.CuRKXX.HJDXZ==null?"":item.CuRKXX.HJDXZ},
                new SqlParameter(){ParameterName="@HJDYJMP", Value = item.CuRKXX.HJDYJMP==null?"":item.CuRKXX.HJDYJMP},
                new SqlParameter(){ParameterName="@HJDYJMPDSH", Value = item.CuRKXX.HJDYJMPDSH==null?"":item.CuRKXX.HJDYJMPDSH},
                new SqlParameter(){ParameterName="@HJDEJMP", Value = item.CuRKXX.HJDEJMP==null?"":item.CuRKXX.HJDEJMP},
                new SqlParameter(){ParameterName="@HJDEJMPDSH", Value = item.CuRKXX.HJDEJMPDSH==null?"":item.CuRKXX.HJDEJMPDSH},
                new SqlParameter(){ParameterName="@JZDXZQH", Value = item.CuRKXX.JZDXZQH==null?"":item.CuRKXX.JZDXZQH},
                new SqlParameter(){ParameterName="@JZDLM", Value = item.CuRKXX.JZDLM==null?"":item.CuRKXX.JZDLM},
                new SqlParameter(){ParameterName="@JZDXZ", Value = item.CuRKXX.JZDXZ==null?"":item.CuRKXX.JZDXZ},
                new SqlParameter(){ParameterName="@JZDYJMP", Value = item.CuRKXX.JZDYJMP==null?"":item.CuRKXX.JZDYJMP},
                 
                new SqlParameter(){ParameterName="@JZDYJMPDSH", Value = item.CuRKXX.JZDYJMPDSH==null?"":item.CuRKXX.JZDYJMPDSH},
                new SqlParameter(){ParameterName="@JZDEJMP", Value = item.CuRKXX.JZDEJMP==null?"":item.CuRKXX.JZDEJMP},
                new SqlParameter(){ParameterName="@JZDEJMPDSH", Value = item.CuRKXX.JZDEJMPDSH==null?"":item.CuRKXX.JZDEJMPDSH},
                new SqlParameter(){ParameterName="@POXM", Value = item.CuRKXX.POXM==null?"":item.CuRKXX.POXM},
                new SqlParameter(){ParameterName="@POZJHM", Value = item.CuRKXX.POZJHM==null?"":item.CuRKXX.POZJHM},
                new SqlParameter(){ParameterName="@ZY", Value = item.CuRKXX.ZY==null?"":item.CuRKXX.ZY},
                new SqlParameter(){ParameterName="@ZJXY", Value = item.CuRKXX.ZJXY==null?"":item.CuRKXX.ZJXY},
                new SqlParameter(){ParameterName="@BYZK", Value = item.CuRKXX.BYZK==null?"":item.CuRKXX.BYZK},
                new SqlParameter(){ParameterName="@SG", Value = item.CuRKXX.SG==null?"":item.CuRKXX.SG},
                new SqlParameter(){ParameterName="@XX", Value = item.CuRKXX.XX==null?"":item.CuRKXX.XX},
                new SqlParameter(){ParameterName="@GJ", Value = item.CuRKXX.GJ==null?"":item.CuRKXX.GJ},
                new SqlParameter(){ParameterName="@MAPID", Value = item.CuRKXX.MAPID},

                new SqlParameter(){ParameterName="@HJFWID", Value = item.CuRKXX.HJFWID},
                new SqlParameter(){ParameterName="@JZFWID", Value = item.CuRKXX.JZFWID},
                new SqlParameter(){ParameterName="@BZ", Value = item.CuRKXX.BZ==null?"":item.CuRKXX.BZ},
                new SqlParameter(){ParameterName="@FwId", Value = item.CuRKXX.FwId}                              

            };
                            cm.CommandText = sql;
                            cm.Parameters.Clear();
                            cm.Parameters.AddRange(sqlparams);
                            cm.ExecuteNonQuery();
                        }
                    }
                }
                trans.Commit();
                resu = cuId;



            }
            catch
            {
                trans.Rollback();
                resu = 0;
            }
            finally
            {
                cnn.Close();
                trans.Dispose();
                cnn.Dispose();
            }


            return resu;
        }

        public bool UpdateBAS_RKXXModel(BAS_RKXXModel rkxxModel, List<RKXXFamilyMemberActionObj> cuMembers = null)
        {
            if (rkxxModel == null)
                return false;
            int resu = 0;
            System.Data.SqlClient.SqlConnection cnn = new System.Data.SqlClient.SqlConnection(ah.GetConnectionStr());
            System.Data.SqlClient.SqlCommand cm = cnn.CreateCommand();
            cnn.Open();
            System.Data.SqlClient.SqlTransaction trans = cnn.BeginTransaction();
            cm.Transaction = trans;
            try
            {
                rkxxModel.CSRQ = GetCsrqBySfzh(rkxxModel.ZJHM);
                string sql = @"UPDATE [BAS_RKXX]
           SET [XM] = @XM,[XB] = @XB,[MZ] = @MZ,[CSRQ] = @CSRQ,[ZJHM] = @ZJHM,[MQLB] = @MQLB,
           [ZYLB] = @ZYLB,[SSCJ] = @SSCJ,[RKLB] = @RKLB,[HJLB] = @HJLB,[ZT] = @ZT,[JG] = @JG,
           [CSD] = @CSD,[WHCD] = @WHCD,[HYZK] = @HYZK,[JKZK] = @JKZK,[ZZMM] = @ZZMM,[LXFS] = @LXFS,
           [GZDW] = @GZDW,[XZ] = @XZ,[YHZGX] = @YHZGX,[ZXGXSJ] = @ZXGXSJ,[ZJZL] = @ZJZL,[XMQP] = @XMQP,
           [XMSP] = @XMSP,[CYM] = @CYM,[HJDXZQH] = @HJDXZQH,[HJDLM] = @HJDLM,[HJDXZ] = @HJDXZ,
           [HJDYJMP] = @HJDYJMP,[HJDYJMPDSH] = @HJDYJMPDSH,[HJDEJMP] = @HJDEJMP,[HJDEJMPDSH] = @HJDEJMPDSH,
           [JZDXZQH] = @JZDXZQH,[JZDLM] = @JZDLM,[JZDXZ] = @JZDXZ,[JZDYJMP] = @JZDYJMP,[JZDYJMPDSH] = @JZDYJMPDSH,
           [JZDEJMP] = @JZDEJMP,[JZDEJMPDSH] = @JZDEJMPDSH,[POXM] = @POXM,[POZJHM] = @POZJHM,[ZY] = @ZY,[ZJXY] = @ZJXY,
           [BYZK] = @BYZK,[SG] = @SG,[XX] = @XX,[GJ] = @GJ,[MAPID] = @MAPID,[HJFWID] = @HJFWID,[JZFWID] = @JZFWID,[BZ] = @BZ,
           [FwId] = @FwId where ID=@ID ";

                SqlParameter[] sqlparams = new SqlParameter[]
            {
                new SqlParameter(){ParameterName="@XM", Value = rkxxModel.XM},
                new SqlParameter(){ParameterName="@XB", Value = rkxxModel.XB},
                new SqlParameter(){ParameterName="@MZ", Value = rkxxModel.MZ==null?"":rkxxModel.MZ},
                new SqlParameter(){ParameterName="@CSRQ", Value = rkxxModel.CSRQ==null?"":rkxxModel.CSRQ.Value.ToString("yyyy-MM-dd HH:mm:ss")},
                new SqlParameter(){ParameterName="@ZJHM", Value = rkxxModel.ZJHM==null?"":rkxxModel.ZJHM},
                new SqlParameter(){ParameterName="@MQLB", Value = rkxxModel.MQLB==null?"":rkxxModel.MQLB},
                new SqlParameter(){ParameterName="@ZYLB", Value = rkxxModel.ZYLB==null?"":rkxxModel.ZYLB},
                new SqlParameter(){ParameterName="@SSCJ", Value = rkxxModel.SSCJ},
                new SqlParameter(){ParameterName="@RKLB", Value = rkxxModel.RKLB},
                new SqlParameter(){ParameterName="@HJLB", Value = rkxxModel.HJLB},
                new SqlParameter(){ParameterName="@ZT", Value = rkxxModel.ZT},
                new SqlParameter(){ParameterName="@JG", Value = rkxxModel.JG==null?"":rkxxModel.JG},
                new SqlParameter(){ParameterName="@CSD", Value = rkxxModel.CSD==null?"":rkxxModel.CSD},
                new SqlParameter(){ParameterName="@WHCD", Value = rkxxModel.WHCD==null?"":rkxxModel.WHCD},
                new SqlParameter(){ParameterName="@HYZK", Value = rkxxModel.HYZK},              

                new SqlParameter(){ParameterName="@JKZK", Value = rkxxModel.JKZK==null?"":rkxxModel.JKZK},
                new SqlParameter(){ParameterName="@ZZMM", Value = rkxxModel.ZZMM==null?"":rkxxModel.ZZMM},
                new SqlParameter(){ParameterName="@LXFS", Value = rkxxModel.LXFS==null?"":rkxxModel.LXFS},
                new SqlParameter(){ParameterName="@GZDW", Value = rkxxModel.GZDW==null?"":rkxxModel.GZDW},
                new SqlParameter(){ParameterName="@XZ", Value = rkxxModel.XZ==null?"":rkxxModel.XZ},
                new SqlParameter(){ParameterName="@YHZGX", Value = rkxxModel.YHZGX==null?"":rkxxModel.YHZGX},
                new SqlParameter(){ParameterName="@ZXGXSJ", Value = rkxxModel.ZXGXSJ==null?"":rkxxModel.ZXGXSJ.Value.ToString("yyyy-MM-dd HH:mm:ss")},
                new SqlParameter(){ParameterName="@ZJZL", Value = rkxxModel.ZJZL},
                new SqlParameter(){ParameterName="@XMQP", Value = rkxxModel.XMQP==null?"":rkxxModel.XMQP},
                new SqlParameter(){ParameterName="@XMSP", Value = rkxxModel.XMSP==null?"":rkxxModel.XMSP},
                new SqlParameter(){ParameterName="@CYM", Value = rkxxModel.CYM==null?"":rkxxModel.CYM},
                new SqlParameter(){ParameterName="@HJDXZQH", Value = rkxxModel.HJDXZQH==null?"":rkxxModel.HJDXZQH},
                new SqlParameter(){ParameterName="@HJDLM", Value = rkxxModel.HJDLM==null?"":rkxxModel.HJDLM},
                                
                new SqlParameter(){ParameterName="@HJDXZ", Value = rkxxModel.HJDXZ==null?"":rkxxModel.HJDXZ},
                new SqlParameter(){ParameterName="@HJDYJMP", Value = rkxxModel.HJDYJMP==null?"":rkxxModel.HJDYJMP},
                new SqlParameter(){ParameterName="@HJDYJMPDSH", Value = rkxxModel.HJDYJMPDSH==null?"":rkxxModel.HJDYJMPDSH},
                new SqlParameter(){ParameterName="@HJDEJMP", Value = rkxxModel.HJDEJMP==null?"":rkxxModel.HJDEJMP},
                new SqlParameter(){ParameterName="@HJDEJMPDSH", Value = rkxxModel.HJDEJMPDSH==null?"":rkxxModel.HJDEJMPDSH},
                new SqlParameter(){ParameterName="@JZDXZQH", Value = rkxxModel.JZDXZQH==null?"":rkxxModel.JZDXZQH},
                new SqlParameter(){ParameterName="@JZDLM", Value = rkxxModel.JZDLM==null?"":rkxxModel.JZDLM},
                new SqlParameter(){ParameterName="@JZDXZ", Value = rkxxModel.JZDXZ==null?"":rkxxModel.JZDXZ},
                new SqlParameter(){ParameterName="@JZDYJMP", Value = rkxxModel.JZDYJMP==null?"":rkxxModel.JZDYJMP},
                 
                new SqlParameter(){ParameterName="@JZDYJMPDSH", Value = rkxxModel.JZDYJMPDSH==null?"":rkxxModel.JZDYJMPDSH},
                new SqlParameter(){ParameterName="@JZDEJMP", Value = rkxxModel.JZDEJMP==null?"":rkxxModel.JZDEJMP},
                new SqlParameter(){ParameterName="@JZDEJMPDSH", Value = rkxxModel.JZDEJMPDSH==null?"":rkxxModel.JZDEJMPDSH},
                new SqlParameter(){ParameterName="@POXM", Value = rkxxModel.POXM==null?"":rkxxModel.POXM},
                new SqlParameter(){ParameterName="@POZJHM", Value = rkxxModel.POZJHM==null?"":rkxxModel.POZJHM},
                new SqlParameter(){ParameterName="@ZY", Value = rkxxModel.ZY==null?"":rkxxModel.ZY},
                new SqlParameter(){ParameterName="@ZJXY", Value = rkxxModel.ZJXY==null?"":rkxxModel.ZJXY},
                new SqlParameter(){ParameterName="@BYZK", Value = rkxxModel.BYZK==null?"":rkxxModel.BYZK},
                new SqlParameter(){ParameterName="@SG", Value = rkxxModel.SG==null?"":rkxxModel.SG},
                new SqlParameter(){ParameterName="@XX", Value = rkxxModel.XX==null?"":rkxxModel.XX},
                new SqlParameter(){ParameterName="@GJ", Value = rkxxModel.GJ==null?"":rkxxModel.GJ},
                new SqlParameter(){ParameterName="@MAPID", Value = rkxxModel.MAPID},

                new SqlParameter(){ParameterName="@HJFWID", Value = rkxxModel.HJFWID},
                new SqlParameter(){ParameterName="@JZFWID", Value = rkxxModel.JZFWID},
                new SqlParameter(){ParameterName="@BZ", Value = rkxxModel.BZ==null?"":rkxxModel.BZ},
                new SqlParameter(){ParameterName="@FwId", Value = rkxxModel.FwId},
                new SqlParameter(){ParameterName="@ID", Value = rkxxModel.ID}           

            };

                cm.CommandText = sql;
                cm.Parameters.Clear();
                cm.Parameters.AddRange(sqlparams);
                var re = cm.ExecuteNonQuery();


                if (cuMembers != null && cuMembers.Count > 0)
                {
                    foreach (var item in cuMembers)
                    {
                        if (item.CuRKXX.ID == 0)
                        {
                            //item.CuAch.ParentID = arc.pid;
                            item.CuRKXX.CSRQ = GetCsrqBySfzh(item.CuRKXX.ZJHM);
                            sql = @"INSERT INTO [BAS_RKXX]
           ([XM],[XB],[MZ],[CSRQ],[ZJHM],[MQLB],[ZYLB],[SSCJ],[RKLB],[HJLB],[ZT],[JG],[CSD],[WHCD],[HYZK],
           [JKZK],[ZZMM],[LXFS],[GZDW],[XZ],[YHZGX],[ZXGXSJ],[ZJZL],[XMQP],[XMSP],[CYM],[HJDXZQH],[HJDLM],
           [HJDXZ],[HJDYJMP],[HJDYJMPDSH],[HJDEJMP],[HJDEJMPDSH],[JZDXZQH],[JZDLM],[JZDXZ],[JZDYJMP],
           [JZDYJMPDSH],[JZDEJMP],[JZDEJMPDSH],[POXM],[POZJHM],[ZY],[ZJXY],[BYZK],[SG],[XX],[GJ],[MAPID],
           [HJFWID],[JZFWID],[BZ],[FwId])
            VALUES  (@XM2,@XB2,@MZ2,@CSRQ2,@ZJHM2,@MQLB2,@ZYLB2,@SSCJ2,@RKLB2,@HJLB2,@ZT2,@JG2,@CSD2,@WHCD2,@HYZK2,
            @JKZK2,@ZZMM2,@LXFS2,@GZDW2,@XZ2,@YHZGX2,@ZXGXSJ2,@ZJZL2,@XMQP2,@XMSP2,@CYM2,@HJDXZQH2,@HJDLM2,
            @HJDXZ2,@HJDYJMP2,@HJDYJMPDSH2,@HJDEJMP2,@HJDEJMPDSH2,@JZDXZQH2,@JZDLM2,@JZDXZ2,@JZDYJMP2,
            @JZDYJMPDSH2,@JZDEJMP2,@JZDEJMPDSH2,@POXM2,@POZJHM2,@ZY2,@ZJXY2,@BYZK2,@SG2,@XX2,@GJ2,@MAPID2,
            @HJFWID2,@JZFWID2,@BZ2,@FwId2) SELECT  @@IDENTITY  as  ID";
                            sqlparams = new SqlParameter[]
            {
                new SqlParameter(){ParameterName="@XM2", Value = item.CuRKXX.XM},
                new SqlParameter(){ParameterName="@XB2", Value = item.CuRKXX.XB},
                new SqlParameter(){ParameterName="@MZ2", Value = item.CuRKXX.MZ==null?"":item.CuRKXX.MZ},
                new SqlParameter(){ParameterName="@CSRQ2", Value = item.CuRKXX.CSRQ==null?"":item.CuRKXX.CSRQ.Value.ToString("yyyy-MM-dd HH:mm:ss")},
                new SqlParameter(){ParameterName="@ZJHM2", Value = item.CuRKXX.ZJHM==null?"":item.CuRKXX.ZJHM},
                new SqlParameter(){ParameterName="@MQLB2", Value = item.CuRKXX.MQLB==null?"":item.CuRKXX.MQLB},
                new SqlParameter(){ParameterName="@ZYLB2", Value = item.CuRKXX.ZYLB==null?"":item.CuRKXX.ZYLB},
                new SqlParameter(){ParameterName="@SSCJ2", Value = item.CuRKXX.SSCJ},
                new SqlParameter(){ParameterName="@RKLB2", Value = item.CuRKXX.RKLB},
                new SqlParameter(){ParameterName="@HJLB2", Value = item.CuRKXX.HJLB},
                new SqlParameter(){ParameterName="@ZT2", Value = item.CuRKXX.ZT},
                new SqlParameter(){ParameterName="@JG2", Value = item.CuRKXX.JG==null?"":item.CuRKXX.JG},
                new SqlParameter(){ParameterName="@CSD2", Value = item.CuRKXX.CSD==null?"":item.CuRKXX.CSD},
                new SqlParameter(){ParameterName="@WHCD2", Value = item.CuRKXX.WHCD==null?"":item.CuRKXX.WHCD},
                new SqlParameter(){ParameterName="@HYZK2", Value = item.CuRKXX.HYZK},              

                new SqlParameter(){ParameterName="@JKZK2", Value = item.CuRKXX.JKZK==null?"":item.CuRKXX.JKZK},
                new SqlParameter(){ParameterName="@ZZMM2", Value = item.CuRKXX.ZZMM==null?"":item.CuRKXX.ZZMM},
                new SqlParameter(){ParameterName="@LXFS2", Value = item.CuRKXX.LXFS==null?"":item.CuRKXX.LXFS},
                new SqlParameter(){ParameterName="@GZDW2", Value = item.CuRKXX.GZDW==null?"":item.CuRKXX.GZDW},
                new SqlParameter(){ParameterName="@XZ2", Value = item.CuRKXX.XZ==null?"":item.CuRKXX.XZ},
                new SqlParameter(){ParameterName="@YHZGX2", Value = item.CuRKXX.YHZGX==null?"":item.CuRKXX.YHZGX},
                new SqlParameter(){ParameterName="@ZXGXSJ2", Value = item.CuRKXX.ZXGXSJ==null?"":item.CuRKXX.ZXGXSJ.Value.ToString("yyyy-MM-dd HH:mm:ss")},
                new SqlParameter(){ParameterName="@ZJZL2", Value = item.CuRKXX.ZJZL},
                new SqlParameter(){ParameterName="@XMQP2", Value = item.CuRKXX.XMQP==null?"":item.CuRKXX.XMQP},
                new SqlParameter(){ParameterName="@XMSP2", Value = item.CuRKXX.XMSP==null?"":item.CuRKXX.XMSP},
                new SqlParameter(){ParameterName="@CYM2", Value = item.CuRKXX.CYM==null?"":item.CuRKXX.CYM},
                new SqlParameter(){ParameterName="@HJDXZQH2", Value = item.CuRKXX.HJDXZQH==null?"":item.CuRKXX.HJDXZQH},
                new SqlParameter(){ParameterName="@HJDLM2", Value = item.CuRKXX.HJDLM==null?"":item.CuRKXX.HJDLM},
                                
                new SqlParameter(){ParameterName="@HJDXZ2", Value = item.CuRKXX.HJDXZ==null?"":item.CuRKXX.HJDXZ},
                new SqlParameter(){ParameterName="@HJDYJMP2", Value = item.CuRKXX.HJDYJMP==null?"":item.CuRKXX.HJDYJMP},
                new SqlParameter(){ParameterName="@HJDYJMPDSH2", Value = item.CuRKXX.HJDYJMPDSH==null?"":item.CuRKXX.HJDYJMPDSH},
                new SqlParameter(){ParameterName="@HJDEJMP2", Value = item.CuRKXX.HJDEJMP==null?"":item.CuRKXX.HJDEJMP},
                new SqlParameter(){ParameterName="@HJDEJMPDSH2", Value = item.CuRKXX.HJDEJMPDSH==null?"":item.CuRKXX.HJDEJMPDSH},
                new SqlParameter(){ParameterName="@JZDXZQH2", Value = item.CuRKXX.JZDXZQH==null?"":item.CuRKXX.JZDXZQH},
                new SqlParameter(){ParameterName="@JZDLM2", Value = item.CuRKXX.JZDLM==null?"":item.CuRKXX.JZDLM},
                new SqlParameter(){ParameterName="@JZDXZ2", Value = item.CuRKXX.JZDXZ==null?"":item.CuRKXX.JZDXZ},
                new SqlParameter(){ParameterName="@JZDYJMP2", Value = item.CuRKXX.JZDYJMP==null?"":item.CuRKXX.JZDYJMP},
                 
                new SqlParameter(){ParameterName="@JZDYJMPDSH2", Value = item.CuRKXX.JZDYJMPDSH==null?"":item.CuRKXX.JZDYJMPDSH},
                new SqlParameter(){ParameterName="@JZDEJMP2", Value = item.CuRKXX.JZDEJMP==null?"":item.CuRKXX.JZDEJMP},
                new SqlParameter(){ParameterName="@JZDEJMPDSH2", Value = item.CuRKXX.JZDEJMPDSH==null?"":item.CuRKXX.JZDEJMPDSH},
                new SqlParameter(){ParameterName="@POXM2", Value = item.CuRKXX.POXM==null?"":item.CuRKXX.POXM},
                new SqlParameter(){ParameterName="@POZJHM2", Value = item.CuRKXX.POZJHM==null?"":item.CuRKXX.POZJHM},
                new SqlParameter(){ParameterName="@ZY2", Value = item.CuRKXX.ZY==null?"":item.CuRKXX.ZY},
                new SqlParameter(){ParameterName="@ZJXY2", Value = item.CuRKXX.ZJXY==null?"":item.CuRKXX.ZJXY},
                new SqlParameter(){ParameterName="@BYZK2", Value = item.CuRKXX.BYZK==null?"":item.CuRKXX.BYZK},
                new SqlParameter(){ParameterName="@SG2", Value = item.CuRKXX.SG==null?"":item.CuRKXX.SG},
                new SqlParameter(){ParameterName="@XX2", Value = item.CuRKXX.XX==null?"":item.CuRKXX.XX},
                new SqlParameter(){ParameterName="@GJ2", Value = item.CuRKXX.GJ==null?"":item.CuRKXX.GJ},
                new SqlParameter(){ParameterName="@MAPID2", Value = item.CuRKXX.MAPID},

                new SqlParameter(){ParameterName="@HJFWID2", Value = item.CuRKXX.HJFWID},
                new SqlParameter(){ParameterName="@JZFWID2", Value = item.CuRKXX.JZFWID},
                new SqlParameter(){ParameterName="@BZ2", Value = item.CuRKXX.BZ==null?"":item.CuRKXX.BZ},
                new SqlParameter(){ParameterName="@FwId2", Value = item.CuRKXX.FwId}                              

            };
                            cm.CommandText = sql;
                            cm.Parameters.Clear();
                            cm.Parameters.AddRange(sqlparams);
                            cm.ExecuteNonQuery();
                        }
                        else if (item.ActionMode == 1)
                        {
                            item.CuRKXX.CSRQ = GetCsrqBySfzh(item.CuRKXX.ZJHM);
                            sql = @"UPDATE [BAS_RKXX]
           SET [XM] = @XM1,[XB] = @XB1,[MZ] = @MZ1,[CSRQ] = @CSRQ1,[ZJHM] = @ZJHM1,[MQLB] = @MQLB1,
           [ZYLB] = @ZYLB1,[SSCJ] = @SSCJ1,[RKLB] = @RKLB1,[HJLB] = @HJLB1,[ZT] = @ZT1,[JG] = @JG1,
           [CSD] = @CSD1,[WHCD] = @WHCD1,[HYZK] = @HYZK1,[JKZK] = @JKZK1,[ZZMM] = @ZZMM1,[LXFS] = @LXFS1,
           [GZDW] = @GZDW1,[XZ] = @XZ1,[YHZGX] = @YHZGX1,[ZXGXSJ] = @ZXGXSJ1,[ZJZL] = @ZJZL1,[XMQP] = @XMQP1,
           [XMSP] = @XMSP1,[CYM] = @CYM1,[HJDXZQH] = @HJDXZQH1,[HJDLM] = @HJDLM1,[HJDXZ] = @HJDXZ1,
           [HJDYJMP] = @HJDYJMP1,[HJDYJMPDSH] = @HJDYJMPDSH1,[HJDEJMP] = @HJDEJMP1,[HJDEJMPDSH] = @HJDEJMPDSH1,
           [JZDXZQH] = @JZDXZQH1,[JZDLM] = @JZDLM1,[JZDXZ] = @JZDXZ1,[JZDYJMP] = @JZDYJMP1,[JZDYJMPDSH] = @JZDYJMPDSH1,
           [JZDEJMP] = @JZDEJMP1,[JZDEJMPDSH] = @JZDEJMPDSH1,[POXM] = @POXM1,[POZJHM] = @POZJHM1,[ZY] = @ZY1,[ZJXY] = @ZJXY1,
           [BYZK] = @BYZK1,[SG] = @SG1,[XX] = @XX1,[GJ] = @GJ1,[MAPID] = @MAPID1,[HJFWID] = @HJFWID1,[JZFWID] = @JZFWID1,[BZ] = @BZ1,
           [FwId] = @FwId1 where ID=@ID1 ";

                            sqlparams = new SqlParameter[]
            {
                new SqlParameter(){ParameterName="@XM1", Value = item.CuRKXX.XM},
                new SqlParameter(){ParameterName="@XB1", Value = item.CuRKXX.XB},
                new SqlParameter(){ParameterName="@MZ1", Value = item.CuRKXX.MZ==null?"":item.CuRKXX.MZ},
                new SqlParameter(){ParameterName="@CSRQ1", Value = item.CuRKXX.CSRQ==null?"":item.CuRKXX.CSRQ.Value.ToString("yyyy-MM-dd HH:mm:ss")},
                new SqlParameter(){ParameterName="@ZJHM1", Value = item.CuRKXX.ZJHM==null?"":item.CuRKXX.ZJHM},
                new SqlParameter(){ParameterName="@MQLB1", Value = item.CuRKXX.MQLB==null?"":item.CuRKXX.MQLB},
                new SqlParameter(){ParameterName="@ZYLB1", Value = item.CuRKXX.ZYLB==null?"":item.CuRKXX.ZYLB},
                new SqlParameter(){ParameterName="@SSCJ1", Value = item.CuRKXX.SSCJ},
                new SqlParameter(){ParameterName="@RKLB1", Value = item.CuRKXX.RKLB},
                new SqlParameter(){ParameterName="@HJLB1", Value = item.CuRKXX.HJLB},
                new SqlParameter(){ParameterName="@ZT1", Value = item.CuRKXX.ZT},
                new SqlParameter(){ParameterName="@JG1", Value = item.CuRKXX.JG==null?"":item.CuRKXX.JG},
                new SqlParameter(){ParameterName="@CSD1", Value = item.CuRKXX.CSD==null?"":item.CuRKXX.CSD},
                new SqlParameter(){ParameterName="@WHCD1", Value = item.CuRKXX.WHCD==null?"":item.CuRKXX.WHCD},
                new SqlParameter(){ParameterName="@HYZK1", Value = item.CuRKXX.HYZK},              

                new SqlParameter(){ParameterName="@JKZK1", Value = item.CuRKXX.JKZK==null?"":item.CuRKXX.JKZK},
                new SqlParameter(){ParameterName="@ZZMM1", Value = item.CuRKXX.ZZMM==null?"":item.CuRKXX.ZZMM},
                new SqlParameter(){ParameterName="@LXFS1", Value = item.CuRKXX.LXFS==null?"":item.CuRKXX.LXFS},
                new SqlParameter(){ParameterName="@GZDW1", Value = item.CuRKXX.GZDW==null?"":item.CuRKXX.GZDW},
                new SqlParameter(){ParameterName="@XZ1", Value = item.CuRKXX.XZ==null?"":item.CuRKXX.XZ},
                new SqlParameter(){ParameterName="@YHZGX1", Value = item.CuRKXX.YHZGX==null?"":item.CuRKXX.YHZGX},
                new SqlParameter(){ParameterName="@ZXGXSJ1", Value = item.CuRKXX.ZXGXSJ==null?"":item.CuRKXX.ZXGXSJ.Value.ToString("yyyy-MM-dd HH:mm:ss")},
                new SqlParameter(){ParameterName="@ZJZL1", Value = item.CuRKXX.ZJZL},
                new SqlParameter(){ParameterName="@XMQP1", Value = item.CuRKXX.XMQP==null?"":item.CuRKXX.XMQP},
                new SqlParameter(){ParameterName="@XMSP1", Value = item.CuRKXX.XMSP==null?"":item.CuRKXX.XMSP},
                new SqlParameter(){ParameterName="@CYM1", Value = item.CuRKXX.CYM==null?"":item.CuRKXX.CYM},
                new SqlParameter(){ParameterName="@HJDXZQH1", Value = item.CuRKXX.HJDXZQH==null?"":item.CuRKXX.HJDXZQH},
                new SqlParameter(){ParameterName="@HJDLM1", Value = item.CuRKXX.HJDLM==null?"":item.CuRKXX.HJDLM},
                                
                new SqlParameter(){ParameterName="@HJDXZ1", Value = item.CuRKXX.HJDXZ==null?"":item.CuRKXX.HJDXZ},
                new SqlParameter(){ParameterName="@HJDYJMP1", Value = item.CuRKXX.HJDYJMP==null?"":item.CuRKXX.HJDYJMP},
                new SqlParameter(){ParameterName="@HJDYJMPDSH1", Value = item.CuRKXX.HJDYJMPDSH==null?"":item.CuRKXX.HJDYJMPDSH},
                new SqlParameter(){ParameterName="@HJDEJMP1", Value = item.CuRKXX.HJDEJMP==null?"":item.CuRKXX.HJDEJMP},
                new SqlParameter(){ParameterName="@HJDEJMPDSH1", Value = item.CuRKXX.HJDEJMPDSH==null?"":item.CuRKXX.HJDEJMPDSH},
                new SqlParameter(){ParameterName="@JZDXZQH1", Value = item.CuRKXX.JZDXZQH==null?"":item.CuRKXX.JZDXZQH},
                new SqlParameter(){ParameterName="@JZDLM1", Value = item.CuRKXX.JZDLM==null?"":item.CuRKXX.JZDLM},
                new SqlParameter(){ParameterName="@JZDXZ1", Value = item.CuRKXX.JZDXZ==null?"":item.CuRKXX.JZDXZ},
                new SqlParameter(){ParameterName="@JZDYJMP1", Value = item.CuRKXX.JZDYJMP==null?"":item.CuRKXX.JZDYJMP},
                 
                new SqlParameter(){ParameterName="@JZDYJMPDSH1", Value = item.CuRKXX.JZDYJMPDSH==null?"":item.CuRKXX.JZDYJMPDSH},
                new SqlParameter(){ParameterName="@JZDEJMP1", Value = item.CuRKXX.JZDEJMP==null?"":item.CuRKXX.JZDEJMP},
                new SqlParameter(){ParameterName="@JZDEJMPDSH1", Value = item.CuRKXX.JZDEJMPDSH==null?"":item.CuRKXX.JZDEJMPDSH},
                new SqlParameter(){ParameterName="@POXM1", Value = item.CuRKXX.POXM==null?"":item.CuRKXX.POXM},
                new SqlParameter(){ParameterName="@POZJHM1", Value = item.CuRKXX.POZJHM==null?"":item.CuRKXX.POZJHM},
                new SqlParameter(){ParameterName="@ZY1", Value = item.CuRKXX.ZY==null?"":item.CuRKXX.ZY},
                new SqlParameter(){ParameterName="@ZJXY1", Value = item.CuRKXX.ZJXY==null?"":item.CuRKXX.ZJXY},
                new SqlParameter(){ParameterName="@BYZK1", Value = item.CuRKXX.BYZK==null?"":item.CuRKXX.BYZK},
                new SqlParameter(){ParameterName="@SG1", Value = item.CuRKXX.SG==null?"":item.CuRKXX.SG},
                new SqlParameter(){ParameterName="@XX1", Value = item.CuRKXX.XX==null?"":item.CuRKXX.XX},
                new SqlParameter(){ParameterName="@GJ1", Value = item.CuRKXX.GJ==null?"":item.CuRKXX.GJ},
                new SqlParameter(){ParameterName="@MAPID1", Value = item.CuRKXX.MAPID},

                new SqlParameter(){ParameterName="@HJFWID1", Value = item.CuRKXX.HJFWID},
                new SqlParameter(){ParameterName="@JZFWID1", Value = item.CuRKXX.JZFWID},
                new SqlParameter(){ParameterName="@BZ1", Value = item.CuRKXX.BZ==null?"":item.CuRKXX.BZ},
                new SqlParameter(){ParameterName="@FwId1", Value = item.CuRKXX.FwId},
                new SqlParameter(){ParameterName="@ID1", Value = item.CuRKXX.ID}
            };
                            cm.CommandText = sql;
                            cm.Parameters.Clear();
                            cm.Parameters.AddRange(sqlparams);
                            cm.ExecuteNonQuery();
                        }
                        else if (item.ActionMode == 2)
                        {
                            sql = string.Format(@"delete from BAS_RKXX where ID={0}", item.CuRKXX.ID);
                            cm.CommandText = sql;
                            cm.ExecuteNonQuery();
                        }
                    }
                }
                trans.Commit();
                resu = 1;
            }
            catch
            {
                trans.Rollback();
                resu = 0;
            }
            finally
            {
                cnn.Close();
                trans.Dispose();
                cnn.Dispose();
            }

            return resu == 1;
        }

        public List<BAS_RKXXModel> GetRKXXMemberViewDbByFwId(int fwId, int cuRkxxId = 0)
        {
            string sql = string.Format(@"select * from [BAS_RKXX] where JZFwId={0} ", fwId);
            if (cuRkxxId != 0)
                sql += " and Id<>" + cuRkxxId.ToString();

            List<BAS_RKXXModel> ar = new List<BAS_RKXXModel>();
            //sql += " order by ZXGXSJ desc";
            var ds = ah.ExcuteDataSet(sql);
            if (ds == null || ds.Tables.Count < 1)
                return null;
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                BAS_RKXXModel cuBsRkxx = new BAS_RKXXModel();
                cuBsRkxx.ID = Int32.Parse(dr["ID"].ToString());
                cuBsRkxx.BYZK = dr["BYZK"] == DBNull.Value ? "" : dr["BYZK"].ToString();
                cuBsRkxx.BZ = dr["BZ"] == DBNull.Value ? "" : dr["BZ"].ToString();
                cuBsRkxx.CSD = dr["CSD"] == DBNull.Value ? "" : dr["CSD"].ToString();
                cuBsRkxx.CSRQ = dr["CSRQ"] == DBNull.Value ? (DateTime?)null : DateTime.Parse(dr["CSRQ"].ToString());
                cuBsRkxx.CYM = dr["CYM"] == DBNull.Value ? "" : dr["CYM"].ToString();
                cuBsRkxx.GJ = dr["GJ"] == DBNull.Value ? "" : dr["GJ"].ToString();
                cuBsRkxx.GZDW = dr["GZDW"] == DBNull.Value ? "" : dr["GZDW"].ToString();
                cuBsRkxx.HJDEJMP = dr["HJDEJMP"] == DBNull.Value ? "" : dr["HJDEJMP"].ToString();
                cuBsRkxx.HJDEJMPDSH = dr["HJDEJMPDSH"] == DBNull.Value ? "" : dr["HJDEJMPDSH"].ToString();
                cuBsRkxx.HJDLM = dr["HJDLM"] == DBNull.Value ? "" : dr["HJDLM"].ToString();
                cuBsRkxx.HJDXZ = dr["HJDXZ"] == DBNull.Value ? "" : dr["HJDXZ"].ToString();
                cuBsRkxx.HJDXZQH = dr["HJDXZQH"] == DBNull.Value ? "" : dr["HJDXZQH"].ToString();
                cuBsRkxx.HJDYJMP = dr["HJDYJMP"] == DBNull.Value ? "" : dr["HJDYJMP"].ToString();
                cuBsRkxx.HJDYJMPDSH = dr["HJDYJMPDSH"] == DBNull.Value ? "" : dr["HJDYJMPDSH"].ToString();
                cuBsRkxx.HJFWID = dr["HJFWID"] == DBNull.Value ? 0 : Int32.Parse(dr["HJFWID"].ToString());
                cuBsRkxx.HJLB = dr["HJLB"] == DBNull.Value ? 0 : Int32.Parse(dr["HJLB"].ToString());
                cuBsRkxx.HYZK = dr["HYZK"] == DBNull.Value ? 0 : Int32.Parse(dr["HYZK"].ToString());
                cuBsRkxx.JG = dr["JG"] == DBNull.Value ? "" : dr["JG"].ToString();
                cuBsRkxx.JKZK = dr["JKZK"] == DBNull.Value ? "" : dr["JKZK"].ToString();
                cuBsRkxx.JZDEJMP = dr["JZDEJMP"] == DBNull.Value ? "" : dr["JZDEJMP"].ToString();
                cuBsRkxx.JZDEJMPDSH = dr["JZDEJMPDSH"] == DBNull.Value ? "" : dr["JZDEJMPDSH"].ToString();
                cuBsRkxx.JZDLM = dr["JZDLM"] == DBNull.Value ? "" : dr["JZDLM"].ToString();
                cuBsRkxx.JZDXZ = dr["JZDXZ"] == DBNull.Value ? "" : dr["JZDXZ"].ToString();
                cuBsRkxx.JZDXZQH = dr["JZDXZQH"] == DBNull.Value ? "" : dr["JZDXZQH"].ToString();
                cuBsRkxx.JZDYJMP = dr["JZDYJMP"] == DBNull.Value ? "" : dr["JZDYJMP"].ToString();
                cuBsRkxx.JZDYJMPDSH = dr["JZDYJMPDSH"] == DBNull.Value ? "" : dr["JZDYJMPDSH"].ToString();
                cuBsRkxx.JZFWID = dr["JZFWID"] == DBNull.Value ? 0 : Int32.Parse(dr["JZFWID"].ToString());
                cuBsRkxx.LXFS = dr["LXFS"] == DBNull.Value ? "" : dr["LXFS"].ToString();
                cuBsRkxx.MAPID = dr["MAPID"] == DBNull.Value ? 0 : Int32.Parse(dr["MAPID"].ToString());
                cuBsRkxx.MQLB = dr["MQLB"] == DBNull.Value ? "" : dr["MQLB"].ToString();
                cuBsRkxx.MZ = dr["MZ"] == DBNull.Value ? "" : dr["MZ"].ToString();
                cuBsRkxx.POXM = dr["POXM"] == DBNull.Value ? "" : dr["POXM"].ToString();
                cuBsRkxx.POZJHM = dr["POZJHM"] == DBNull.Value ? "" : dr["POZJHM"].ToString();
                cuBsRkxx.RKLB = dr["RKLB"] == DBNull.Value ? 0 : Int32.Parse(dr["RKLB"].ToString());
                cuBsRkxx.SG = dr["SG"] == DBNull.Value ? "" : dr["SG"].ToString();
                cuBsRkxx.SSCJ = dr["SSCJ"] == DBNull.Value ? 0 : Int32.Parse(dr["SSCJ"].ToString());
                cuBsRkxx.WHCD = dr["WHCD"] == DBNull.Value ? "" : dr["WHCD"].ToString();
                cuBsRkxx.XB = dr["XB"] == DBNull.Value ? 0 : Int32.Parse(dr["XB"].ToString());
                cuBsRkxx.XM = dr["XM"] == DBNull.Value ? "" : dr["XM"].ToString();
                cuBsRkxx.XMQP = dr["XMQP"] == DBNull.Value ? "" : dr["XMQP"].ToString();
                cuBsRkxx.XMSP = dr["XMSP"] == DBNull.Value ? "" : dr["XMSP"].ToString();
                cuBsRkxx.XX = dr["XX"] == DBNull.Value ? "" : dr["XX"].ToString();
                cuBsRkxx.XZ = dr["XZ"] == DBNull.Value ? "" : dr["XZ"].ToString();
                cuBsRkxx.YHZGX = dr["YHZGX"] == DBNull.Value ? "" : dr["YHZGX"].ToString();
                cuBsRkxx.ZJHM = dr["ZJHM"] == DBNull.Value ? "" : dr["ZJHM"].ToString();
                cuBsRkxx.ZJXY = dr["ZJXY"] == DBNull.Value ? "" : dr["ZJXY"].ToString();
                cuBsRkxx.ZJZL = dr["ZJZL"] == DBNull.Value ? 0 : Int32.Parse(dr["ZJZL"].ToString());
                cuBsRkxx.ZT = dr["ZT"] == DBNull.Value ? 0 : Int32.Parse(dr["ZT"].ToString());
                cuBsRkxx.ZXGXSJ = dr["ZXGXSJ"] == DBNull.Value ? (DateTime?)null : DateTime.Parse(dr["ZXGXSJ"].ToString());
                cuBsRkxx.ZY = dr["ZY"] == DBNull.Value ? "" : dr["ZY"].ToString();
                cuBsRkxx.ZYLB = dr["ZYLB"] == DBNull.Value ? "" : dr["ZYLB"].ToString();
                cuBsRkxx.ZZMM = dr["ZZMM"] == DBNull.Value ? "" : dr["ZZMM"].ToString();
                cuBsRkxx.FwId = dr["JZFwId"] == DBNull.Value ? 0 : Int32.Parse(dr["JZFwId"].ToString());
                ar.Add(cuBsRkxx);
            }
             
            return ar;
        }

        public List<DataDictionaryItemModel> GetDictionaryByParentId(int parentId)
        {
            string sqlStr = string.Format(@"select * from DataDictionaryItem where ParentId={0}", parentId);

            var dt = ah.GetDataSet(sqlStr);
            if (dt != null && dt.Rows.Count < 1)
                return new List<DataDictionaryItemModel>();
            List<DataDictionaryItemModel> dicts = new List<DataDictionaryItemModel>();
            foreach (DataRow dr in dt.Rows)
            {
                DataDictionaryItemModel di = new DataDictionaryItemModel()
                {
                    Id = Int32.Parse(dr["Id"].ToString()),
                    DictCode = dr["DictCode"] == DBNull.Value ? "" : dr["DictCode"].ToString(),
                    DictPinYin = dr["DictPinYin"] == DBNull.Value ? "" : dr["DictPinYin"].ToString(),
                    DictValue = dr["DictValue"] == DBNull.Value ? "" : dr["DictValue"].ToString(),
                    ParentId = dr["ParentId"] == DBNull.Value ? 0 : Int32.Parse(dr["ParentId"].ToString())
                };
                dicts.Add(di);
            }

            return dicts;

        }

        public List<DataDictionaryItemModel> GetChildDictionaryByDictName(string dictName)
        {
            string sqlStr = string.Format(@"select * from DataDictionaryItem where ParentId=
            (select top 1 Id from DataDictionary where DictName='{0}')", dictName);

            var dt = ah.GetDataSet(sqlStr);
            if (dt != null && dt.Rows.Count < 1)
                return new List<DataDictionaryItemModel>();
            List<DataDictionaryItemModel> dicts = new List<DataDictionaryItemModel>();
            foreach (DataRow dr in dt.Rows)
            {
                DataDictionaryItemModel di = new DataDictionaryItemModel()
                {
                    Id = Int32.Parse(dr["Id"].ToString()),
                    DictCode = dr["DictCode"] == DBNull.Value ? "" : dr["DictCode"].ToString(),
                    DictPinYin = dr["DictPinYin"] == DBNull.Value ? "" : dr["DictPinYin"].ToString(),
                    DictValue = dr["DictValue"] == DBNull.Value ? "" : dr["DictValue"].ToString(),
                    ParentId = dr["ParentId"] == DBNull.Value ? 0 : Int32.Parse(dr["ParentId"].ToString())
                };
                dicts.Add(di);
            }

            return dicts;

        }

        public List<string> GetArchivesByCondition(int j, string xqStr = "")
        {
            string sql = string.Empty;
            if (j == 1)
            {
                sql = string.Format(@"select XM+','+isnull(jzhm,'') from BAS_RKXX where XM<>'' and XM is not null");
            }
            else if (j == 2)
                sql = string.Format(@"select XM from BAS_RKXX where XM<>'' and XM is not null");
            else if (j == 3)
                sql = string.Format(@"select jzhm from BAS_RKXX where zjhm<>'' and zjhm is not null");
            else if (j == 4)
                sql = string.Format(@"select zjhm+','+isnull(XM,'') from BAS_RKXX where zjhm<>'' and zjhm is not null");
            else if (j == 5)
                sql = string.Format(@"select XM+','+isnull(zjhm,' ')+','+isnull(LXFS,' ') from BAS_RKXX where XM<>'' and XM is not null");
            else if (j == 6)
                sql = string.Format(@"select XM+','+isnull(zjhm,' ')+','+isnull(LXFS,' ')+','+isnull(JZDXZ,' ') from BAS_RKXX where XM<>'' and XM is not null");
            else if (j == 7)
                sql = string.Format(@"select distinct JZDXZ from BAS_RKXX where JZDXZ<>'' and JZDXZ is not null");

            else if (j == 8)
                sql = string.Format(@"select XM+','+isnull(zjhm,'') from BAS_RKXX where zzmm='党员' and XM<>'' and XM is not null");
            else if (j == 9)
                sql = string.Format(@"select zjhm+','+isnull(XM,'') from BAS_RKXX where zzmm='党员' and zjhm<>'' and zjhm is not null");
            else if (j == 10)
                sql = string.Format(@"select distinct JZDXZ from BAS_RKXX where zzmm='党员' and JZDXZ<>'' and JZDXZ is not null");

            else if (j == 11)
                sql = string.Format(@"select XM+','+isnull(zjhm,'') from BAS_RKXX where zzmm<>'党员' and XM<>'' and XM is not null");

            else if (j == 12)
                sql = string.Format(@"select zjhm+','+isnull(XM,'') from BAS_RKXX where zzmm<>'党员' and zjhm<>'' and zjhm is not null");

            else if (j == 13)
                sql = string.Format(@"select zjhm+','+isnull(XM,'') from BAS_RKXX where zzmm='党员' and zjhm<>'' and zjhm is not null 
                        and not exists (select 0 from DY_DYXX where zjhm=IDCARD) ");

            else if (j == 14)
                sql = string.Format(@"select XM+','+isnull(zjhm,'') from BAS_RKXX where XM<>'' and XM is not null and zzmm='党员' 
                        and not exists (select 0 from DY_DYXX where zjhm=IDCARD)");

            else if (j == 15)
                sql = string.Format(@"select zjhm from BAS_RKXX where DATEDIFF(day,DATEADD(year,18,csrq),GETDATE())>=0 ");

            else if (j == 17)
                sql = string.Format(@"select distinct REPLACE(JZDXZ,'{0}','') from BAS_RKXX where JZDXZ<>'' and JZDXZ is not null 
and JZDXZ like '{0}%'", xqStr);

            var ds = ah.ExcuteDataSet(sql);
            if (ds == null || ds.Tables.Count < 1)
                return null;
            List<string> AliceInWonderland = new List<string>();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                AliceInWonderland.Add(ds.Tables[0].Rows[i][0].ToString());
            }
            return AliceInWonderland;
        }
        #endregion
    }
}
